package com.yjj.springboot3.config;

import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 通用配置
 *
 * @author yjj
 */
@Configuration
public class ResourcesConfig implements WebMvcConfigurer {

    @Resource
    private FileConfig fileConfig;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /** 本地文件上传路径 */
        registry.addResourceHandler(fileConfig.getResourcePrefix() + "/**")
                .addResourceLocations("file:" + fileConfig.getProfile() + "/");

        /** 静态资源路径 */
        registry.addResourceHandler("/static/**")
                .addResourceLocations("classpath:/static/");

        /** 文档资源路径 */
        registry.addResourceHandler("/doc.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
}
